﻿#if UNITY_EDITOR
using System.IO;
using UnityEditor;
/// <summary>
/// 选择的资源抽象
/// </summary>
public abstract class AbsESF_EditorCollectAsset : AbsESF_EditorAsset<AbsESF_EditorCollectAsset>
{
    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="_pathOrGuid">资源路径或guid</param>
    public AbsESF_EditorCollectAsset(string _pathOrGuid)
    {
        if (File.Exists(_pathOrGuid) || Directory.Exists(_pathOrGuid))
        {
            path = _pathOrGuid;
            guid = AssetDatabase.AssetPathToGUID(_pathOrGuid);
        }
        else
        {
            guid = _pathOrGuid;
            path = AssetDatabase.GUIDToAssetPath(_pathOrGuid);
        }
        guidHashCode = path.ESF_UniqueHashCode();

        ext = Path.GetExtension(path);
        name = Path.GetFileName(path);
        nameWithoutExtension = Path.GetFileNameWithoutExtension(path);
        directory = Path.GetDirectoryName(path).ESF_TransPathSeparatorCharToUnityChar();

        isFile = File.Exists(path);
        isDirectory = Directory.Exists(path);
        classify = enESF_AssetClassify.All;
        if (isFile)
        {
            classify = enESF_AssetClassify.File;
        }
        else if (isDirectory)
        {
            classify = enESF_AssetClassify.Folder;
        }
        OnAfterConstructor();
    }

    #region OnAfterConstructor 在构造函数后
    /// <summary>
    /// 在构造函数后
    /// </summary>
    protected virtual void OnAfterConstructor() { }
    #endregion

    /// <summary>
    /// 解析
    /// </summary>
    /// <param name="_index">索引</param>
    public void Resolve(int _index = -1)
    {        
        OnAfterResolve(_index);
    }

    /// <summary>
    /// OnAfterResolve
    /// </summary>
    /// <param name="_index">索引</param>
    protected virtual void OnAfterResolve(int _index) { }

    /// <summary>
    /// 资源guidHashCode
    /// </summary>
    public int guidHashCode { get; private set; }
    /// <summary>
    /// 资源guid
    /// </summary>
    public string guid { get; private set; }
    /// <summary>
    /// 资源路径
    /// </summary>
    public string path { get; private set; }
    /// <summary>
    /// 是否是目录
    /// </summary>
    public bool isDirectory { get; private set; }
    /// <summary>
    /// 是否是文件
    /// </summary>
    public bool isFile { get; private set; }
    /// <summary>
    /// 资源分类
    /// </summary>
    public enESF_AssetClassify classify { get; private set; }
    /// <summary>
    /// 后缀
    /// </summary>
    public string ext { get; private set; }
    /// <summary>
    /// 名称
    /// </summary>
    public string name { get; private set; }
    /// <summary>
    /// 无后缀名称
    /// </summary>
    public string nameWithoutExtension { get; private set; }
    /// <summary>
    /// 目录
    /// </summary>
    public string directory { get; private set; }
}
#endif
